import scrapy
from scrapy.selector import HtmlXPathSelector

from one.items import OneItem

class RuSpider(scrapy.Spider):
    name = "ru"
    allowed_domains = ["runoob.com"]
    start_urls = (
        'http://www.runoob.com/',
    )

    def parse(self, response):
        hxs = HtmlXPathSelector(response)
        items = []
        for si in ('//div[@class="codelist codelist-desktop cate%s"]/a' %i for i in range(1,11)):
            sites = hxs.select(si)
            for site in sites:
                item = OneItem()
                item['title'] = site.select('h4/text()').extract()
                item['link'] = site.select('@href').extract()
                item['strongs'] = site.select('text()|strong/text()').extract()[2]
                items.append(item)
        return items

